package com.zte.claa.inficombo.csa.app.service.dev.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zte.claa.inficombo.csa.app.dao.mysql.impl.DevBaseMapper;
import com.zte.claa.inficombo.csa.app.model.dev.DevBase;
import com.zte.claa.inficombo.csa.app.model.dev.DevPagePara;
import com.zte.claa.inficombo.csa.app.model.dev.SensorDevEuiPV;
import com.zte.claa.inficombo.csa.app.model.redis.ProjectDev;
import com.zte.claa.inficombo.csa.app.service.csa.impl.BaseCacheManager;
import com.zte.claa.inficombo.csa.app.service.dev.DevBaseService;

@Service
public class DevBaseServiceImpl implements DevBaseService {
	@Autowired
	private DevBaseMapper devBaseMapper;
	
	@Autowired
	private BaseCacheManager cacheManager;
	
	@Override
	public List<DevBase> queryDevs(DevPagePara pp) throws Exception {
		return this.devBaseMapper.queryDevs(pp);
	}
	
	@Override
	public List<DevBase> queryDevsByAppeui(DevPagePara pp, String appeui) throws Exception {
		return this.devBaseMapper.queryDevsByAppeui(pp, appeui);
	}

	@Override
	public DevBase queryDevByEui(String deveui) throws Exception {
		return this.devBaseMapper.queryDevByEui(deveui);
	}

	@Override
	public int queryAllDevTotalNum() throws Exception {
		return this.devBaseMapper.queryAllDevTotalNum();
	}

	@Override
	public List<SensorDevEuiPV> querySensorDevEuiPVs(DevPagePara pp) throws Exception {
		return this.devBaseMapper.querySensorDevEuiPVs(pp);
	}

	@Override
	public SensorDevEuiPV querySensorDevEuiPV(String sensorid) throws Exception {
		return this.devBaseMapper.querySensorDevEuiPV(sensorid);
	}

	@Override
	public void addSensorDevEuiPV(SensorDevEuiPV pv) throws Exception {
		this.devBaseMapper.addSensorDevEuiPV(pv);
		// 添加到缓存...
		this.cacheManager.putSensorDevEuiPV(pv);
	}

	@Override
	public int remvoeSensorDevEuiPV(String sensorid) throws Exception {
		this.cacheManager.removeSensorDevEuiPV(sensorid);
		return this.devBaseMapper.remvoeSensorDevEuiPV(sensorid);
	}

	@Override
	public int remvoeSensorDevEuiPVByDev(String deveui) throws Exception {
		return this.devBaseMapper.remvoeSensorDevEuiPVByDev(deveui);
	}

	/**
	 * 查询指定deveui对应的dev完整信息
	 * 
	 * @param deveui
	 * @return
	 * @throws Exception
	 */
	public ProjectDev queryProjectDevByEui(String deveui) throws Exception {
		return this.devBaseMapper.queryProjectDevByEui(deveui);
	}
	
	/**
	 * 修改设备坐标
	 * 
	 * @param deveui
	 * @param devaddr
	 * @return
	 * @throws Exception
	 */
	public int updateDevCoordinate(String deveui, double gpslat, double gpslng, int gpsalt) throws Exception{
		return this.devBaseMapper.updateDevCoordinate(deveui, gpslat, gpslng, gpsalt);
	}
	
	/**
	 * 修改设备位置
	 * 
	 * @param deveui
	 * @param devaddr
	 * @return
	 * @throws Exception
	 */
	public int updateDevAddress(String deveui, String devaddr) throws Exception{
		return this.devBaseMapper.updateDevAddress(deveui, devaddr);
	}
}
